{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "weight_initialization.ipynb",
      "provenance": [],
      "authorship_tag": "ABX9TyPtW+giNWLyqmhXRsp+3Y+Z",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/SummerLife/EmbeddedSystem/blob/master/MachineLearning/gist/weight_initialization.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MypzEOCzB-yR",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "006025dd-dd76-4b8d-a7df-d51fd1855ae6"
      },
      "source": [
        "from keras.models import Sequential\n",
        "from keras.layers import Dense, Activation\n",
        "\n",
        "model = Sequential([\n",
        "    Dense(16, input_shape=(1,5), activation='relu'),\n",
        "    Dense(32, activation='relu', kernel_initializer='glorot_uniform'),\n",
        "    Dense(2, activation='softmax')\n",
        "])"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Using TensorFlow backend.\n"
          ],
          "name": "stderr"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7GZPzHM_CHJq",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 255
        },
        "outputId": "083746b7-34f7-4a1b-8437-4d78aa4366e3"
      },
      "source": [
        "model.summary()"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Model: \"sequential_1\"\n",
            "_________________________________________________________________\n",
            "Layer (type)                 Output Shape              Param #   \n",
            "=================================================================\n",
            "dense_1 (Dense)              (None, 1, 16)             96        \n",
            "_________________________________________________________________\n",
            "dense_2 (Dense)              (None, 1, 32)             544       \n",
            "_________________________________________________________________\n",
            "dense_3 (Dense)              (None, 1, 2)              66        \n",
            "=================================================================\n",
            "Total params: 706\n",
            "Trainable params: 706\n",
            "Non-trainable params: 0\n",
            "_________________________________________________________________\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lmdVI2ddCL3W",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from contextlib import redirect_stdout\n",
        "\n",
        "with open('modelsummary.txt', 'w') as f:\n",
        "    with redirect_stdout(f):\n",
        "        model.summary()"
      ],
      "execution_count": 6,
      "outputs": []
    }
  ]
}